/**
 * 箭头函数
 * 解决的问题
 * 1.缩减代码
 * 2.改变this的指向
 */


//演变过程
 const double1=function(number){
     return number*2;
 }
 //删掉function
 const double2=(number)=>{
    return number*2;
 }
 //删掉花括号和return
 const double3=(number)=>number*2;
//一个参数时还可以继续删掉参包裹数的括号
const double4=number=>number*2;
//多个参数时则必须添加括号
const sum=(number1,number2)=>number1+number2;
//多行代码最好加花括号否则不好解读
const double5=(number1,number2)=>{
    sum1=number1+number2
    return sum1;
}

 console.log(double1(20));
 console.log(double2(20));
 console.log(double3(20));
 console.log(double4(20));
 console.log(sum(10,20)); 
 console.log(double5(10,20)); 


 /**场景
  * 
  * map一个数组，让数组的值以double形式展现
  */
 const numbers=[1,2,3];
 var newNumbers=numbers.map(number=> number*2);
 console.log(newNumbers);

 //改变this的指向
 //es5方法1
 const team={
     members:["Henry","Elyse"],
     teamName:"es6",
     teamSummary:function(){
         //保存this的指向
         let self=this;
         return this.members.map(function(member){
             //this不知道该指向谁
             return `${member}隶属于${self.teamName}小组`;
         })
     }
 }
console.log(team.teamSummary());
//方法2：利用bind
const team1={
    members:["Henry","Elyse"],
    teamName:"es6",
    teamSummary:function(){
        return this.members.map(function(member){
            //this不知道该指向谁
            return `${member}隶属于${this.teamName}小组`;
        }.bind(this))
    }
}
console.log(team1.teamSummary());
//箭头函数

const team2={
    members:["Henry","Elyse"],
    teamName:"es6",
    teamSummary:function(){
        //this指向的就是team对象
        return this.members.map((member)=>`${member}隶属于${this.teamName}小组`);
    }
}
console.log(team2.teamSummary());